package com.template.mapper;

import com.template.dto.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into user(name,imageUrl,createTime,sex,phone,state,account,password) values(#{name},#{imageUrl},#{createTime},#{sex},#{phone},#{state},#{account},#{password})")
    @Options(useGeneratedKeys = true,keyProperty = "id")//将自增的id填充到user
    void add(User user);

    @Select("select * from user order by createTime DESC ")
    List<User> getListById();

    //分页查询
    //查询总记录数
//    @Select("select count(*) from user")
    public Long count();
    //分页查询获取列表数据
//    @Select("select * from user")

    @Delete("delete from user where id=#{id}")
    void delById(Long id);

    @Select("select * from user where id=#{id}")
    User getEditById(Long id);

    @Update("update user set name=#{name},imageUrl=#{imageUrl},sex=#{sex},phone=#{phone},state=#{state},account=#{account},password=#{password} where id=#{id}")
    void editUserById(User user);

    @Select("select * from user")
    List<User> exportExcelUser();

    @Select("select * from user where account=#{arg0} and state=#{arg1}")
    User login(String account,Integer state);

    @Delete("delete from mealanduser  where userId=#{id}")
    void delMealAndUserById(Long id);

    @Insert("insert into loginlogs(userId,name,loginCreateTime,account) values(#{id},#{name},#{createTime},#{account})")
    void loginLogs(User user2);
}
